/**
  ******************************************************************************
  * @file    USART/HalfDuplex/stm32f10x_it.c 
  * @author  MCD Application Team
  * @version V3.4.0
  * @date    10/15/2010
  * @brief   Main Interrupt Service Routines.
  *          This file provides template for all exceptions handler and peripherals
  *          interrupt service routine.
  ******************************************************************************
  * @copy
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
  */ 

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_it.h"
#include "midi_usart.h"
#include "3310lcd.h"
#include "midi_keyboard.h"
#include "midi_menu.h"
#include "diskio.h"

 extern uint8_t Unidentified_Data[30];
 extern  char usart_status;
 extern uint8_t key ;


/** @addtogroup STM32F10x_StdPeriph_Examples
  * @{
  */

/** @addtogroup USART_HalfDuplex
  * @{
  */ 

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/******************************************************************************/
/*            Cortex-M3 Processor Exceptions Handlers                         */
/******************************************************************************/

/**
  * @brief  This function handles NMI exception.
  * @param  None
  * @retval None
  */
void NMI_Handler(void)
{
}

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
  */
void HardFault_Handler(void)
{
  	
	LedOn();
	LCD_Clear();
	LCD_GotoXY(3,2);
	LCD_Str("Hard Fault");

  	while (1){}
}

/**
  * @brief  This function handles Memory Manage exception.
  * @param  None
  * @retval None
  */
void MemManage_Handler(void)
{
  /* Go to infinite loop when Memory Manage exception occurs */
  	LCD_Clear();
	LCD_GotoXY(3,2);
	LCD_Str("Mem Manage");
  while (1)
  {
  }
}

/**
  * @brief  This function handles Bus Fault exception.
  * @param  None
  * @retval None
  */
void BusFault_Handler(void)
{
  /* Go to infinite loop when Bus Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles Usage Fault exception.
  * @param  None
  * @retval None
  */
void UsageFault_Handler(void)
{
  /* Go to infinite loop when Usage Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles SVCall exception.
  * @param  None
  * @retval None
  */
void SVC_Handler(void)
{
}

/**
  * @brief  This function handles Debug Monitor exception.
  * @param  None
  * @retval None
  */
void DebugMon_Handler(void)
{
}

/**
  * @brief  This function handles PendSV_Handler exception.
  * @param  None
  * @retval None
  */
void PendSV_Handler(void)
{
}

/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
/*void SysTick_Handler(void)
{
} */

/******************************************************************************/
/*                 STM32F10x Peripherals Interrupt Handlers                   */
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
/*  available peripheral interrupt handler's name please refer to the startup */
/*  file (startup_stm32f10x_xx.s).                                            */
/******************************************************************************/

/**
  * @brief  This function handles PPP interrupt request.
  * @param  None
  * @retval None
  */
/*void PPP_IRQHandler(void)
{
}*/

/**
  * @}
  */ 

/**
  * @}
  */ 



void DMA1_Channel2_IRQHandler(void)	   // usart 3
{
DMA_InitTypeDef DMA_InitStructure;
	
	if(DMA_GetITStatus(DMA1_IT_TC2))    	
	{

		DMA_ClearITPendingBit(DMA1_IT_TC2);



	    DMA_DeInit(MIDI_DMA_Tx_CHANNEL);   // USART_Tx
	    DMA_InitStructure.DMA_PeripheralBaseAddr = MIDI_DR_Base;
	    DMA_InitStructure.DMA_MemoryBaseAddr = (u32)Unidentified_Data;
	    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
	    DMA_InitStructure.DMA_BufferSize = 30;
	    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
	    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
	    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
	    DMA_InitStructure.DMA_Mode = 	DMA_Mode_Circular;
	    DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
	    DMA_Init(MIDI_DMA_Tx_CHANNEL, &DMA_InitStructure);


	  
		/* Enable USARTy DMA Rx and TX request */
	  	USART_DMACmd(MIDI_USART, USART_DMAReq_Rx | USART_DMAReq_Tx, ENABLE);  	
	
		// Enable DMA Channel
	    DMA_Cmd(MIDI_DMA_Tx_CHANNEL, ENABLE);
	  
	  	/* Enable the MIDI_USART */
	  	USART_Cmd(MIDI_USART, ENABLE);

	}
}




/**
  * @brief  This function handles TIM2 global interrupt request.
  * @param  None
  * @retval None
  */
void TIM2_IRQHandler(void)
{

	TIM_ClearFlag(TIM2, TIM_FLAG_Update);
	disk_timerproc(); /* to be called every 10ms */
  
}


/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
